home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / wdj0797.zip / SDKANN.ZIP / SOURCE.ZIP / ANNCONV.C < prev    next >
C/C++ Source or Header  |  1997-01-09  |  4KB  |  171 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #ifndef TRUE
  6. #   define TRUE 1
  7. #endif
  8. #ifndef FALSE
  9. #   define FALSE 0
  10. #endif
  11.  
  12. char   *Value(char*In)
  13.     {
  14.     while(*In && *In != ' ' && *In != '\t')
  15.         ++In;
  16.     while(*In && (*In == ' ' || *In == '\t'))
  17.         ++In;
  18.     return In;
  19.     }
  20.  
  21. void    OutputString(FILE* Out, char *Line)
  22.     {
  23.     while(*Line)
  24.         {
  25.         if(*Line == '\"')
  26.             fprintf(Out, "\\042");
  27.         else if(*Line == '\\')
  28.             fprintf(Out, "\\\\");
  29.         else
  30.             fprintf(Out, "%c", *Line);
  31.         ++Line;
  32.         }
  33.     }
  34.  
  35.  
  36. void    OutputLine(FILE* Out, char *Line)
  37.     {
  38.     while(*Line)
  39.         {
  40.         if(*Line == '\"')
  41.             fprintf(Out, "\\042");
  42.         else if(*Line == '\\')
  43.             fprintf(Out, "\\\\");
  44.         else
  45.             fprintf(Out, "%c", *Line);
  46.         ++Line;
  47.         }
  48.     }
  49.  
  50. int GetLine(FILE* In, char*Out)
  51.     {
  52.     if(!fgets(Out, 127, In))
  53.         return FALSE;
  54.     else
  55.         {
  56.         int Len = strlen(Out);
  57.         if(Len > 0)
  58.             Out[Len-1]  = '\0';
  59.         return Len;
  60.         }
  61.     }
  62.  
  63.  
  64. void DoAnnotation(FILE* In, FILE* Out, char* Line, int Num)
  65.     {
  66.     int     NewLine;
  67.     char    Type[128];
  68.     char    Topic[128];
  69.     char    Keyword[128];
  70.     char   *Number = strchr(Line, '#');
  71.     GetLine(In, Type);
  72.     GetLine(In, Topic);
  73.     GetLine(In, Keyword);
  74.     if(!strcmpi(Value(Type), "Win3.1"))
  75.         strcpy(Type, "win31wh.hlp");
  76.     else if(!strcmpi(Value(Type), "Win16"))
  77.         strcpy(Type, "win31wh.hlp");
  78.     else if(!strncmp(Value(Type), "MFC", 3))
  79.         strcpy(Type, "mfc30.hlp");
  80.     else if(!strcmpi(Value(Type), "Win32"))
  81.         strcpy(Type, "win32.hlp");
  82.     else
  83.         printf("Bad type? : '%s'\n", Value(Type));
  84.     fprintf(Out, "%d\tRCDATA\nbegin\n", Num);
  85.     fprintf(Out, "\t\"%s\\0\"\n", Type);
  86.     fprintf(Out, "\t\"%s\t%s\\0\"\n", Number, Value(Topic));
  87.  
  88.     fprintf(Out, "\t\"");
  89.     OutputString(Out, Value(Keyword));
  90.     fprintf(Out, "\\0\"\n");
  91.  
  92.     fprintf(Out, "\t\"%s\\0\"\n", Value(Topic));
  93.     fprintf(Out, "\n");
  94.     fprintf(Out, "\"%s\"\n", Line);
  95.     NewLine = FALSE;
  96.     while(GetLine(In, Line))
  97.         {
  98.         int Len = strlen(Line);
  99.         if(!strncmp(Line, "--------", 8))
  100.             break;
  101.         if(Len == 0)
  102.             {
  103.             if(!NewLine)
  104.                 fprintf(Out, "\"\\r\\n\"\n");
  105.             fprintf(Out, "\"\\r\\n\"\n");
  106.             NewLine = TRUE;
  107.             }
  108.         else if(Len > 0)
  109.             {
  110.             if(Line[0] == ' ' || Line[0] == '\t')
  111.                 if(!NewLine)
  112.                     {
  113.                     NewLine     = TRUE;
  114.                     fprintf(Out, "\"\\r\\n\"\n");
  115.                     }
  116.             if(Line[Len-1] == '^' || Line[0] == ' ' || Line[0] == '\t')
  117.                 {
  118.                 if(Line[Len-1] == '^')
  119.                     Line[Len-1] = '\0';
  120.                 fprintf(Out, "\"");
  121.                 OutputLine(Out, Line);
  122.                 fprintf(Out, "\\r\\n\"\n", Line);
  123.                 NewLine = TRUE;
  124.                 }
  125.             else
  126.                 {
  127.                 fprintf(Out, "\"");
  128.                 OutputLine(Out, Line);
  129.                 fprintf(Out, " \"\n");
  130.                 NewLine = FALSE;
  131.                 }
  132.             }
  133.         }
  134.     fprintf(Out, "\"\\0\\0\\0\\0\"\nend\n\n");
  135.     }
  136.  
  137. void    Process(FILE *In, FILE *Out)
  138.     {
  139.     static char    Line[1024];
  140.     int Num = 0;
  141.     while(GetLine(In, Line))
  142.         {
  143.         if(!strncmp(Line, "WDJ SDK Annotation #", 20)
  144.         || !strncmp(Line, "WDJ MFC Annotation #", 20))
  145.             {
  146.             DoAnnotation(In, Out, Line, ++Num);
  147.             }
  148.         else if(!strncmp(Line, "WDJ ", 4))
  149.             printf("Bad line? : %s\n", Line);
  150.         }
  151.     printf( "Processed %d annotations\n", Num);
  152.     }
  153.  
  154.  
  155. void    main()
  156.     {
  157.     FILE *Fin   = fopen("..\\sdkann.txt", "r");
  158.     FILE *Fout  = fopen("annotate.rc", "w");
  159.     if(!Fin)
  160.         {
  161.         printf("Could not open '..\\sdkann.txt' for input\n");
  162.         exit(EXIT_FAILURE);
  163.         }
  164.     if(!Fout)
  165.         {
  166.         printf("Could not open 'annotate.rc' for output\n");
  167.         exit(EXIT_FAILURE);
  168.         }
  169.     Process(Fin, Fout);
  170.     }
  171.